package com.qdu.study_app.Activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.qdu.study_app.R;

import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.UpdateListener;

public class Activity_cpwd extends AppCompatActivity {

    private Button cpwd;
    private TextView pwd1;
    private TextView pwd2;
    private TextView pwd_old;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cpwd);
        init();
    }
    public void init(){
        cpwd = findViewById(R.id.cpwd_button);
        pwd1 = findViewById(R.id.cpwd_p1);
        pwd2 = findViewById(R.id.cpwd_p2);
        pwd_old = findViewById(R.id.pwd_old);
        cpwd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String old = pwd_old.getText().toString().trim();
                String p1 = pwd1.getText().toString().trim();
                String p2 = pwd2.getText().toString().trim();
                if(p1.equals(p2)){
                    BmobUser.updateCurrentUserPassword(old, p2, new UpdateListener() {
                        @Override
                        public void done(BmobException e) {
                            Intent intent = new Intent(Activity_cpwd.this,Login_first.class);
                            startActivity(intent);
                            BmobUser.logOut();
                            finish();
                        }
                    });
                }else {
                    System.out.println("----------------------------------");
                }

            }
        });
    }
}